package com.efast.dmom.mgmt.controller.mes.barcode;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.bean.mes.barcode.BarCodeRuleBean;
import com.efast.dmom.mgmt.bean.mes.barcode.BarCodeRuleItemBean;
import com.efast.dmom.mgmt.service.mes.barcode.BarCodeRuleService;

@Controller
@RequestMapping("/BarCodeRule")
public class BarCodeRuleController {
	
	@Autowired
	BarCodeRuleService barcodeRuleService ;
// /{pConfigId}/{barcode}
	@RequestMapping(value = "validateBarCode")
	public @ResponseBody ResultBean validateBarCode(@RequestBody Map<String,Object> map) {
		int pConfigId = Integer.parseInt(map.get("pConfigId").toString());  
		String barcode = map.get("param").toString();
		return barcodeRuleService.validateBarCode(pConfigId, barcode);
	}
	
	@RequestMapping(value = "/refreshCache/{pConfigId}")
	public @ResponseBody ResultBean refreshCache(@PathVariable("pConfigId") int pConfigId) {

		return barcodeRuleService.refreshCache(pConfigId);
	}
	
	//更新条码规则
	@RequestMapping(value = "/updateBarcodeRule")
	public @ResponseBody ResultBean updateBarcodeRule(@RequestBody BarCodeRuleBean barCodeRuleBean) {
		 ResultBean result = barcodeRuleService.updateBarcodeRule(barCodeRuleBean);
		 return result;
	}
	
	//更新条码规则Item
	@RequestMapping(value = "/updateBarcodeRuleItem")
	public @ResponseBody ResultBean updateBarcodeRuleItem(@RequestBody BarCodeRuleItemBean barCodeRuleItemBean) {
		ResultBean result = barcodeRuleService.updateBarcodeRuleItem(barCodeRuleItemBean);
		 return result;
	}
}
